package com.learn.threadpool;

import com.learn.Util.TimeUtils;
import com.learn.constant.MathConstant;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * NewScheduledThreadPool
 *
 * 创建一个定长线程池，支持定时及周期性任务执行
 */
public class NewScheduledThreadPoolTest {

    public static void main(String[] args) {

        int j = MathConstant.INT_ZERO;

        System.out.println(TimeUtils.getDateStr() + " start ");

        ScheduledExecutorService service = Executors.newScheduledThreadPool(MathConstant.INT_ONE);

        service.scheduleAtFixedRate(new MyThread3(j++),
                MathConstant.INT_FIVE, MathConstant.INT_20, TimeUnit.SECONDS);

        service.scheduleAtFixedRate(new MyThread3(j), MathConstant.INT_THREE, MathConstant.INT_20, TimeUnit.SECONDS);

    }


}

